package com.bw.ivideoproject.login

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.ivideoproject.entity.UserEntity
import com.bw.ivideoproject.home.HomeModel
import com.bw.lib_mvvm.BaseViewModel
import kotlinx.coroutines.launch

class LoginViewModel : BaseViewModel() {

    private val model: LoginModel by lazy {
        getModel(LoginModel::class.java)
    }

    val loginLiveData = MutableLiveData<UserEntity>()
    val registerLiveData = MutableLiveData<UserEntity>()


    fun login(username:String,password:String){
        viewModelScope.launch {
            var (code,data,msg) = model.login(username, password)
            if(code == 0){
                loginLiveData.value = data
            }
        }
    }

    fun register(username:String,password:String){
        viewModelScope.launch {
            var (code,data,msg) = model.register(username, password)
            if(code == 0){
                registerLiveData.value = data
            }
        }
    }
}